<%@ page contentType="text/html;charset=UTF-8"%>
<%@page import="java.util.Date"%>
<%@ include file="/app/common/header.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title>微型企业自有资金使用情况表</title>
		<link href="<%=basePath%>/app/main/style/inputpage.css"
			rel="stylesheet" type="text/css" />
	</head>
	<body>
		<form id="inputForm"
			action="<%=basePath%>app/sys/selfmoney/selfmoney!save" method="post">
			<input type="hidden" name="id" id="id" value="${id}" />
			<table width="100%" border="0" id="topSpace">
				<tr>
					<td></td>
				</tr>
			</table>
			<div id="edit">
				<table border="0" align="center" cellpadding="2" cellspacing="1" id="tableAddCon" width="90%">
					<tr>
						<th colspan="4" class="stitle">
							微型企业自有资金使用情况表
						</th>
					</tr>
					<tr>
						<th width='15%'>企业名称:</th>
						<td width='35%'>
							<s:select id="compSelect" onchange="compChange(this.value)" name="entity.comp.id" list="comps" listKey="id" listValue="compName" headerKey="" headerValue="===请选择企业名称==="></s:select>
							<span style="font-size:12px;color:red"><s:fielderror fieldName="msg.compName" /></span>&nbsp;
						</td>
						<th width='15%'>注册资金:</th>
						<td width='35%'>
							<span id="zhuceMoney"></span>&nbsp;
						</td>
					</tr>
					<tr>
						<th width='15%'>自筹资金:</th>
						<td width='35%'>
							<span id="selfTouzhiMoney"></span>&nbsp;
						</td>
						<th width='15%'>财政补助:</th>
						<td width='35%'>
							<span id="govBuzhuMoney"></span>&nbsp;
						</td>
					</tr>
					<tr>
						<th width='15%'>开户银行:</th>
						<td width='35%'>
							<span id="bank"></span>&nbsp;
						</td>
						<th width='15%'>银行账号:</th>
						<td width='35%'>
							<span id="bankNo"></span>&nbsp;
						</td>
					</tr>
					<tr>
						<th width='15%'>成立时间:</th>
						<td width='35%'>
							<span id="chengliDate"></span>&nbsp;
						</td>
						<th width='15%'>联系人:</th>
						<td width='35%'>
							<span id="name"></span>&nbsp;
						</td>
					</tr>
					<tr>
						<th width='15%'>联系电话:</th>
						<td width='35%'>
							<span id="phone"></span>&nbsp;
						</td>
						<th width='15%'>&nbsp;</th>
						<td width='35%'>
							&nbsp;
						</td>
					</tr>
					</table>
					<div align="left" style="padding-left:10px">
							<input style="width:80px" class="submit" type="button" value="增加行" onclick="additem()"/>
							</div>				
					<table id="moneyitems" border="0" align="center" cellpadding="2" cellspacing="1" id="tableAddCon" width="90%">
					<tr>
						<th width='80px'>序号</th>
						<th width='100px'>时间</th>
						<th width='200px'>使用项目</th>
						<th width='100px'>金额</th>
						<th width='80px'>支付方式</th>
						<th >支付对象</th>
						<th width='150px'>开户行</th>
						<th width='150px'>银行账号</th>
						<th width='50px'>操作</th>
					</tr>
					<c:if test="${empty id}">
						<tr align='center'>
							<td><input style='width:95%' class='nestedText' name='items[0].serialNo' type='text' /></td>
							<td><input style='width:95%' class='Wdate' type='text' name='items[0].useDate' onfocus='WdatePicker()' /></td>
							<td><input style='width:95%' class='nestedText' name='items[0].useFor' type='text' /></td>
							<td><input style='width:95%' class='nestedText' name='items[0].amount' type='text' /></td>
							<td><input style='width:95%' class='nestedText' name='items[0].payMethod' type='text' /></td>
							<td><input style='width:95%' class='nestedText' name='items[0].payFor' type='text' /></td>
							<td><input style='width:95%' class='nestedText' name='items[0].bank' type='text' /></td>
							<td><input style='width:95%' class='nestedText' name='items[0].bankNo' type='text' /></td>
							<td></td>
						</tr>
					</c:if>
					<c:if test="${!empty id}">
						<c:forEach items="${entity.items}" var="item" varStatus="status">
							<tr align='center' id="id${status.index }">
								<td><input style='width:95%' class='nestedText' name='items[${status.index }].serialNo' type='text' value='${item.serialNo }'/></td>
								<td><input style='width:95%' class='Wdate' type='text' name='items[${status.index }].useDate' onfocus='WdatePicker()' value='<fmt:formatDate value="${item.useDate }" pattern="yyyy-MM-dd"/>'/></td>
								<td><input style='width:95%' class='nestedText' name='items[${status.index }].useFor' type='text' value='${item.useFor }'/></td>
								<td><input style='width:95%' class='nestedText' name='items[${status.index }].amount' type='text' value='${item.amount }'/></td>
								<td><input style='width:95%' class='nestedText' name='items[${status.index }].payMethod' type='text' value='${item.payMethod }'/></td>
								<td><input style='width:95%' class='nestedText' name='items[${status.index }].payFor' type='text' value='${item.payFor }'/></td>
								<td><input style='width:95%' class='nestedText' name='items[${status.index }].bank' type='text' value='${item.bank }'/></td>
								<td><input style='width:95%' class='nestedText' name='items[${status.index }].bankNo' type='text' value='${item.bankNo }'/></td>
								<td><input style='width:50px' class='submit' type='button' value='删' onclick="removeRow('id${status.index }')"/></td>
							</tr>
						</c:forEach>
					</c:if>
					
					
					</table>
					<table border="0" align="center" cellpadding="2" cellspacing="1" id="tableAddCon" width="90%">
					<tr>
						<td colspan="9" height="50px">
							<span style="width:30px"></span>我单位郑重承诺：以上交易情况真实、客观，无编造、变造、虚设和隐瞒等虚假内容，若出现与真实情况不符的愿意承担相应的责任。    <br>
							<span style="width:100px"></span>特此承诺。<br>
							<span style="width:30px"></span>企业负责人签字：<input class="nestedText" name="entity.chief" value="${entity.chief }" type="text"/>      （企业公章）<span style="width:100px"></span>  时间 ：<input class="Wdate" type="text" name="qianzhiDate" value="<fmt:formatDate value="${qianzhiDate}" pattern="yyyy-MM-dd"/>"  onfocus="WdatePicker()" />
						</td>
					</tr>
					</table>
					<tr>
      		<th align="center" colspan="4" style="padding:5px">
      					 <c:if test="${user.type eq 'high'}">
							<input type="submit" class="submit" value="提交" />
							</c:if>
							&nbsp;
							<input type="button" class="submit" value="返回"
								onclick="javascript:location.href='<%=basePath%>app/sys/selfmoney/selfmoney'" />
						</th>
					</tr>
				

			</div>
			</div>
			
		</form>
		<div style="text-align:left;margin-left:20px">
		<span style="font-size:12px;color:red">
				备注：<br>
				 1、支付方式为现金的，可不填写支付对象的开户行和银行账号；<br>
				 2、本表应附相应的支付凭证；<br>
				 3、本表可续页。
			</span>
			</div>
			<script type="text/javascript">
				var index = 1;//items的索引
				<c:if test="${!empty id}">
					index = ${itemCount};
				</c:if>
				function compChange(id){
					$.ajax({
				 		  type: "POST",
						  cache: false,
						  url: "<%=basePath %>/app/sys/comp/comp!getCompInfo",
						  dataType: "json",
						  timeout: 30000,
						  data:{id:id},
						  success: function(json){
						  	$("#zhuceMoney").html(json.zhuceMoney+"万");
						  	$("#selfTouzhiMoney").html(json.selfTouzhiMoney+"万");
						  	$("#govBuzhuMoney").html(json.govBuzhuMoney+"万");
						  	$("#bank").html(json.bankAddress);
						  	$("#bankNo").html(json.bankNo);
						  	$("#chengliDate").html(json.chengliDate);
						  	$("#name").html(json.name);
						  	$("#phone").html(json.phone);

						  	<c:if test="${user.type eq 'low'}">
							  	$("#bank").html("***");
							  	$("#bankNo").html("***");
							  	$("#phone").html("***");
							</c:if>
						  }, 
						  error:function(){
						  		Ext.MessageBox.show({
						           title: '提示',
						           msg: '请求失败或超时，请稍后再试！',
						           buttons: Ext.MessageBox.OK,
						           icon: Ext.MessageBox.WARNING
						       });
								return;
						  }	
				 	});
				}

				$(function(){
					var id = $("#id").val();
					if(id!=""){
						var sid = $("#compSelect").val();
						compChange(sid);
					}

					$("#money").blur(function(){
						var v = $(this).val();
						$("#moneyBig").val(DX(v));
					});
				}); 

				function DX(n) {
			        if (!/^(0|[1-9]\d*)(\.\d+)?$/.test(n))
			            return "数据非法";
			        var unit = "千百拾亿千百拾万千百拾元角分", str = "";
			            n += "00";
			        var p = n.indexOf('.');
			        if (p >= 0)
			            n = n.substring(0, p) + n.substr(p+1, 2);
			            unit = unit.substr(unit.length - n.length);
			        for (var i=0; i < n.length; i++)
			            str += '零壹贰叁肆伍陆柒捌玖'.charAt(n.charAt(i)) + unit.charAt(i);
			        return str.replace(/零(千|百|拾|角)/g, "零").replace(/(零)+/g, "零").replace(/零(万|亿|元)/g, "$1").replace(/(亿)万|壹(拾)/g, "$1$2").replace(/^元零?|零分/g, "").replace(/元$/g, "元整");
				}

				function additem(){
					var id = "a<%=new Date().getTime()%>";
					var html ="<tr align='center' id='"+id+"'>"+
						"<td><input style='width:95%' class='nestedText' name='items["+index+"].serialNo' type='text' /></td>"+
						"<td><input style='width:95%' class='Wdate' type='text' name='items["+index+"].useDate' onfocus='WdatePicker()' /></td>"+
						"<td><input style='width:95%' class='nestedText' name='items["+index+"].useFor' type='text' /></td>"+
						"<td><input style='width:95%' class='nestedText' name='items["+index+"].amount' type='text' /></td>"+
						"<td><input style='width:95%' class='nestedText' name='items["+index+"].payMethod' type='text' /></td>"+
						"<td><input style='width:95%' class='nestedText' name='items["+index+"].payFor' type='text' /></td>"+
						"<td><input style='width:95%' class='nestedText' name='items["+index+"].bank' type='text' /></td>"+
						"<td><input style='width:95%' class='nestedText' name='items["+index+"].bankNo' type='text' /></td>"+
						"<td><input style='width:50px' class='submit' type='button' value='删' onclick=\"removeRow('"+id+"')\"/></td>"+
					"</tr>"
					$("#moneyitems").append(html);
					index += 1;
				}
				
				function removeRow(id){
					$("#"+id).remove();
				}
			</script>
	</body>
</html>
